package com.als.healthymananger.controller.impl;

import com.als.healthymananger.controller.ReportsApi;
import com.als.healthymananger.entity.Report;
import com.als.healthymananger.service.ReportsService;
import com.als.healthymananger.utils.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping("/assessment/report")
public class ReportsController implements ReportsApi {
    @Autowired
    private ReportsService reportsService;

    @Override
    public RespBean createReports(Report report) {
        return reportsService.save(report)? RespBean.ok("添加成功"): RespBean.badRequest("添加失败");
    }

    @Override
    public RespBean deleteReports(int reportId) {
        return reportsService.removeById(reportId)? RespBean.ok("删除成功"): RespBean.badRequest("删除失败");
    }

    @Override
    public RespBean updateReports(int reportId, Report report) {
        return reportsService.updateById(report)? RespBean.ok("修改成功"): RespBean.badRequest("删除失败");
    }

    @Override
    public RespBean getReportss(int reportId) {
        Report report = reportsService.getById(reportId);
        return report == null? RespBean.badRequest("获取失败"): RespBean.ok("获取成功", report);
    }
}
